from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from time import sleep

"""
五个必传参：
platformName：平台（android&iOS）
platformVersion：版本号
deviceName：设备名称，可以通过adb devices -l 来获取
appPackage：包名，可以通过 adb shell dumpsys activity acitvies来获取 或者 使用 adb shell pm list packages -3 
appActivity：activity事件，可以通过 adb shell dumpsys activity acitvies 来获取
"""
cap_dict={
  "platformVersion": "7.1.2",
  "platformName": "Android",
  "appPackage": "me.onehome.app",
  "appActivity": ".activity.ActivitySplash_",
  "deviceName": "x1q"
}

driver = webdriver.Remote("http://localhost:4723/wd/hub",cap_dict) # 初始化driver
driver.implicitly_wait(15)

# 点击允许
driver.find_element(MobileBy.ID,"com.android.packageinstaller:id/permission_allow_button").click()

# 点击允许2
driver.find_element(MobileBy.ID,"com.android.packageinstaller:id/permission_allow_button").click()

#点击允许3
driver.find_element(MobileBy.ID,"com.android.packageinstaller:id/permission_allow_button").click()

# 点击同意
driver.find_element(MobileBy.ID,"me.onehome.app:id/tv_agree").click()

# 滑动引导页
sleep(2)

# 滑动第一次
TouchAction(driver).press(x = 866,y = 1236 ).move_to(x =63,y = 1257).release().perform()
sleep(3)
#滑动第二次
TouchAction(driver).press(x = 866,y = 1236 ).move_to(x =63,y = 1257).release().perform()
sleep(3)
#滑动第三次
TouchAction(driver).press(x = 866,y = 1236 ).move_to(x =63,y = 1257).release().perform()

# 点击开启
driver.find_elements(MobileBy.CLASS_NAME,"android.widget.TextView")[2].click()